package com._51cto.healthy.service;

import com._51cto.healthy.base.BaseMapper;
import com._51cto.healthy.content.P;
import com._51cto.healthy.mapper.FoodMapper;
import com._51cto.healthy.pojo.Food;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class FoodServiceImpl implements FoodService{
    @Autowired
    private  FoodMapper foodMapper;
    @Override
    public BaseMapper<Food> getDao() {
        return foodMapper;
    }


    @Override
    public P<Food> findAll(String query, Integer pageSize, Integer pageNum) {
        //分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<Food> all = foodMapper.findAll(query);
        PageInfo<Food> pageInfo = new PageInfo<>(all);
        return new P<Food>().setTotal(pageInfo.getTotal())
                .setPages(pageInfo.getPages())
                .setPageSize(pageInfo.getPageSize())
                .setRows(pageInfo.getList())
                .setPageNum(pageInfo.getPageNum());

    }

    @Override
    public void deleteByPK(Integer pk) {
        FoodService.super.deleteByPK(pk);
    }

    @Override
    public void insert(Food entity) {
        FoodService.super.insert(entity);
    }

    @Override
    public void update(Food entity) {
        FoodService.super.update(entity);
    }
}
